#!/usr/bin/perl
package psql_get_columns;

require Exporter;


our @ISA = qw(Exporter);
our $VERSION = 1.00;
our @EXPORT = qw(psql_get_columns);

use strict;
use warnings;
use DBI;
use DBD::Pg;
use Carp;



#_________________________________________________________________________________________

#	psql_get_columns

#

sub psql_get_columns($$$)
{
	my ($dbh,  $schema,  $table) =@_;
	my $sql_cmd =<<"PL/SQLCMD";
    SELECT 
            column_name 
        FROM 
            information_schema.columns 
        WHERE 
            table_name = '$table' AND
            table_schema = '$schema';
PL/SQLCMD
	my $data = $dbh->selectall_arrayref($sql_cmd)		or croak DBI::errstr. ".";
	return map {$_->[0]} @$data;
}


sub test
{
	my $dbh = DBI->connect( "dbi:Pg:dbname=mouse_final;host=db",
							'postgres',
							'',
							{
								RaiseError => 0,
								AutoCommit => 1,
								PrintError => 0
							}
						)
	or croak "Database connection not made: ".$DBI::errstr.".";
	my @columns = psql_get_columns($dbh, 'taxon',  'prot_coding_introns');
	for (@columns)
	{
		print STDERR "[$_]\n";
	}

}

#test();
1;
